package com.controller;

import com.mapper.DataMapper;
import com.pojo.SClass;
import com.pojo.Sdept;
import com.pojo.Station;
import com.pojo.TopicType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/data")
public class DataController {

    @Autowired
    DataMapper dm;

    // 课题分类-课题总数
    @RequestMapping("/topicTypeScale")
    public Map<String,Object> topicTypeScale() {
        Map<String,Object> map = new HashMap<>();
        int code = 200;
        String msg = "ok";

        List<TopicType> list = dm.getTopicTypeList();
        List<String> name = new ArrayList<>();
        List<Integer> total = new ArrayList<>();
        for (TopicType item : list) {
            name.add(item.getName());
            total.add(dm.getTopicTotalByType(item.getId()));
        }

        map.put("code",code);
        map.put("msg",msg);
        map.put("name",name);
        map.put("total",total);
        return map;
    }

    // 职位-教师
    @RequestMapping("/teacherStation")
    public Map<String,Object> teacherStation() {
        Map<String,Object> map = new HashMap<>();
        int code = 200;
        String msg = "ok";

        map.put("code",code);
        map.put("msg",msg);
        map.put("data",dm.getTeacherStationList());
        return map;
    }

    // 系部-班级-学生总数
    @RequestMapping("/sdeptClassStudents")
    public Map<String,Object> sdeptClassStudents() {
        Map<String,Object> map = new HashMap<>();
        int code = 200;
        String msg = "ok";

        List<Sdept> list = dm.getSdeptList();
        List<String> name = new ArrayList<>();
        List<SClass> sClasses = new ArrayList<>();
        List<Integer> classTotal = new ArrayList<>();
        List<Integer> studentTotal = new ArrayList<>();
        Integer st = 0;
        for (Sdept item : list) {
            st = 0;
            name.add(item.getName());
            sClasses = dm.getClassTotalBySdept(item.getId());
            classTotal.add(sClasses.size());
            for (SClass itea : sClasses) {
                st += dm.getStudentTotalByClass(itea.getId());
            }
            studentTotal.add(st);
        }

        map.put("code",code);
        map.put("msg",msg);
        map.put("sdept",name);
        map.put("classTotal",classTotal);
        map.put("studentTotal",studentTotal);
        return map;
    }

}
